import requests
import unittest
import time

text = "我的测试" + time.strftime("%Y%m%d%H%M%S", time.localtime())

class MeetHereAPITest(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.base_url = "http://118.121.200.162:8085/"
        cls.s = cls.login(cls)
        cls.glo = globals()

    def login(self):
        session = requests.Session()
        url = self.base_url+"loginCheck.do"
        userInfo = {
            "userID": "qk",
            "password": "King20020827@"
        }
        res = session.post(url, data=userInfo)
        assert 200 == res.status_code
        return session
    def test_MessageList(self):
        url = self.base_url + "message/getMessageList"
        res = requests.get(url)
        assert 200 == res.status_code



    def test_1sendMessage(self):
        url = self.base_url+"sendMessage"
        self.glo["content"] = text
        message = {
            "userID": "qk",
            "content": text
        }
        res = self.s.post(url, data=message)
        self.assertEqual(200, res.status_code)

    def test_2findUserList(self):
        url = self.base_url+"message/findUserList"
        data = {
            "page": 1
        }
        res = self.s.get(url, params=data)
        self.assertEqual(200, res.status_code)
        self.assertIn(self.glo["content"], res.text)
        messageID = res.json()[0]["messageID"]
        self.glo["msid"] = messageID

    def test_3delMessage(self):
        url = self.base_url+"delMessage.do"
        msid = {
            "messageID": self.glo["msid"]
        }
        res = self.s.post(url, data=msid)
        self.assertEqual(200, res.status_code)

if __name__ == "__main__":
    unittest.main()
